package com.ruoyi.openapi;

import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.config.BigDataConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.JSONObjectPro;
import com.ruoyi.common.core.domain.OpenApiResult;
import com.ruoyi.common.core.page.AppPage;
import com.ruoyi.common.core.page.Page;
import com.ruoyi.common.enums.YesNoEnum;
import com.ruoyi.common.exception.BigDataException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.http.BigDataResponse;
import com.ruoyi.common.utils.http.CommonResponse;
import com.ruoyi.common.utils.http.HttpRequest;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.openapi.domain.request.*;
import com.ruoyi.openapi.service.OpenApiService;
import com.ruoyi.system.domain.request.reportstatistics.ReportStatisticsListParam;
import com.ruoyi.system.domain.vo.common.DeviceGps;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.utils.ComLbsUtils;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 描述 对外提供的接口
 * 作者 ZhangPing
 * 创建时间 2023/10/26 16:57
 */
@RestController
@Slf4j
public class OpenApiController extends BaseController {

    @Autowired
    private SysLoginService loginService;
    @Autowired
    private OpenApiService openApiService;
    @Autowired
    private BigDataConfig bigDataConfig;
    @Autowired
    private ISysDeptService deptService;

    @Anonymous
    @ApiOperation("获取接口认证token")
    @PostMapping("/getToken")
    public OpenApiResult getToken(String username, String password) {
        String token = loginService.login(username, password, "", "", Constants.LOGIN_TYPE_OPENAPI);
        return OpenApiResult.success(new JSONObjectPro().put("token", token));
    }

    @ApiOperation("获取车辆详情列表")
    @PostMapping("/getVehicleDetailList")
    public OpenApiResult getVehicleDetailList(VehicleDetailListParam param) {
        return OpenApiResult.success(openApiService.getVehicleDetailList(param));
    }

    @ApiOperation("分页获取车辆历史轨迹")
    @PostMapping("/getCarHistoryTrack")
    public OpenApiResult getCarHistoryTrack(CarHistoryTrackParam param) {
        return OpenApiResult.success(openApiService.getCarHistoryTrack(param));
    }

    @ApiOperation("获取车辆历史轨迹")
    @PostMapping("/getCarHistoryTrackList")
    public OpenApiResult getCarHistoryTrackList(CarHistoryTrackParam param) {
        return OpenApiResult.success(openApiService.getCarHistoryTrackList(param));
    }

    @ApiOperation("获取车辆实时定位")
    @PostMapping("/getRealtimePosition")
    public OpenApiResult queryRealtimePosition(@RequestParam String dvo) {
        return OpenApiResult.success(openApiService.queryRealtimePosition(dvo));
    }

    @ApiOperation("实时视频点播")
    @PostMapping("/getRealtimeVideo")
    public OpenApiResult getRealtimeVideo(RealtimeVideoParam param) {
        return OpenApiResult.success(openApiService.getRealtimeVideo(param));
    }

    @ApiOperation("获取车辆在线统计")
    @PostMapping("/getCarOnlineDetail")
    public OpenApiResult getCarOnlineDetail(CarOnlineDetailParam param) {
        return OpenApiResult.success(openApiService.getCarOnlineDetail(param));
    }


    @ApiOperation("获取车辆里程统计")
    @PostMapping("/getCarMileageDetail")
    public OpenApiResult getCarMileageDetail(CarMileageDetailParam param) {
        return OpenApiResult.success(openApiService.getCarMileageDetail(param));
    }

    @ApiOperation("获取地图车辆列表")
    @GetMapping("/getMapVehicleList")
    public OpenApiResult getMapVehicleList() {
        return OpenApiResult.success(openApiService.getMapDeviceList());
    }


}
